package com.hxzy.tms.interceptor;

import org.apache.struts2.ServletActionContext;

import com.hxzy.tms.session.SessionHolder;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

public class AuthorizationInterceptor extends AbstractInterceptor {

	private static final long serialVersionUID = -6391719486772661560L;

	@Override
	public String intercept(ActionInvocation invocation) throws Exception {
	    if (SessionHolder.get() == null) {
            if ("XMLHttpRequest".equals(ServletActionContext.getRequest().getHeader("x-requested-with"))) {
                ServletActionContext.getResponse().getWriter()
                        .println("{\"status\":-1, \"message\":\"access denied.\"}");
                return null;
            }
            return Action.LOGIN;
        }
        return invocation.invoke();
	}

}
